import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:没有重复项数字的全排列
 * User: wangxin
 * Date: 2024-12-23
 * Time: 22:48
 */
public class Test {
    public void permuteRC(ArrayList<Integer> nums, ArrayList<Integer> perm){
        if(nums.isEmpty()){
            res.add(new ArrayList<Integer>(perm));
            return;
        }
        for(int i = 0; i < nums.size();i++){
            Integer a = nums.remove(i);
            perm.add(a);
            permuteRC(nums,perm);
            nums.add(i,a);
            perm.remove(perm.size()-1);
        }

    }
    ArrayList<ArrayList<Integer>> res = new ArrayList<ArrayList<Integer>> ();
    public ArrayList<ArrayList<Integer>> permute (int[] num) {
        // write code here
        Arrays.sort(num);
        ArrayList<Integer> nums = new ArrayList<Integer>();
        for(int i = 0;i < num.length;i++)
            nums.add(num[i]);

        permuteRC(nums,new ArrayList<Integer>());
        return res;
    }
}
